{template 'common/header'}
<ul class="nav nav-tabs">
    <li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'display'))}">管理分类</a></li>
    <li {if $operation == 'post' && empty($item['id'])}class="active"{/if}><a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'post'))}">添加分类</a></li>
    {if $operation == 'post'  && !empty($item['id'])}
    <li class="active"><a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'post', 'id' => $item['id']))}">编辑考卷分类</a></li>
    {/if}
</ul>
{if $operation == 'post'}
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit="return formcheck()">
        <input type="hidden" name="parentid" value="{$parent['id']}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                分类编辑
            </div>
            <div class="panel-body">
                {if !empty($parentid)}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
                    <div class="col-sm-9 col-xs-12 form-control-static">
                        {$parent['cname']}
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type='text' id='displayorder' name='displayorder' value="{$item['displayorder']}" class='form-control' />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type='text' id='cname' name='cname' value="{$item['cname']}" class='form-control' />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="description" class="form-control" cols="70">{$item['description']}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='status' value='0' {if $item['status']==0}checked{/if}/> 隐藏
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value='1' {if $item['status']==1}checked{/if}/> 显示
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
    </form>
</div>

<script type="text/javascript">
    function formcheck(){
        if($("#cname").isEmpty()){
            Tip.focus("cname","请输入分类名称!","right");
            return false;
        }
        return true;
    }
</script>
{elseif $operation == 'display'}
<div class="main">
    <div class="category panel panel-default">
        <div class="panel-body table-responsive">
            <form action="" method="post" onsubmit="return formcheck(this)">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th style="width:10px;"></th>
                        <th style="width:100px;">显示顺序</th>
                        <th style="width:120px;">分类名称</th>
                        <th style="width:100px;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $category $row}
                    <tr>
                        <td>{if count($children[$row['id']]) > 0}<a href="javascript:;"><i class="fa fa-chevron-down"></i></a>{/if}</td>
                        <td><input type="text" class="form-control " name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
                        <td>
                            <div class="type-parent">{$row['cname']}&nbsp;&nbsp;
                                {if empty($row['parentid'])}
                                <a href="{php echo $this->createWebUrl('bbs_category', array('parentid' => $row['id'], 'op' => 'post'))}"><i class="fa fa-plus-circle"></i> 添加子分类</a>{/if}
                            </div>
                        </td>
                        <td>
                            <a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'post', 'id' => $row['id']))}"title="编辑" data-toggle="tooltip" data-placement="bottom" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                            <a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除" data-toggle="tooltip" data-placement="bottom" class="btn btn-default btn-sm"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {loop $children[$row['id']] $row}
                    <tr>
                        <td></td>
                        <td><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
                        <td><div class="type-child">{$row['cname']}&nbsp;&nbsp;</div></td>
                        <td>
                            <a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'post', 'id' => $row['id']))}" title="编辑" data-toggle="tooltip" data-placement="bottom" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                            <a href="{php echo $this->createWebUrl('bbs_category', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;"title="删除" data-toggle="tooltip" data-placement="bottom" class="btn btn-default btn-sm"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    {/loop}
                    <tr>
                        <td></td>
                        <td colspan="3">
                            <input name="submit" type="submit" class="btn btn-primary" value="提交">
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('bbs_category', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加新分类</a>
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
{/if}
<script>
    require(['bootstrap'],function($){
        $('.btn').tooltip();
    });
</script>
{template 'common/footer'}
